/**
 * url地址
 */
var WEB_URL = '';
/**
 * 全局控制弹出层对象
 */
var DIV_CTRL = {};

/**
 * 取出所有jgGrid的字符串，并转化成需要的请求模式
 * @param obj
 * @return
 */
function getParamsFromGridObj(obj) {
	var ids = obj.jqGrid('getDataIDs');
	var len = ids.length;
	var str = '';
	for(var i=0; i<len; i++) {
		var obji = obj.jqGrid('getRowData', ids[i]);
		for(var p in obji) {
			if(obji[p].indexOf('\<INPUT')==-1 && obji[p].indexOf('\<input')==-1) {
				str += p + '' + obji[p] + '&';
			}
		}
	}
	str = str.substr(0, str.length-1);
	return str;
}

/**
 * 去除空格
 */
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

/**
 * 验证是否为空
 * @param str
 * @return
 */
function validateStr(str) {
	if(str && str.trim()!='') {
		return true;
	}
	return false;
}


//window.onresize = onResize;

function onResize() {
	var _w = document.body.clientWidth || document.documentElement.clientWidth;
	alert(_w);
	if(_w > 500) {
		$('contentLayer').style.left = parseInt((_w - 500)/2) + 'px';
		$('headBackgroundD').style.width = _w + 'px';
		$('bodyBackgroundD').style.width = _w + 'px';
	}
	/*
	var _h =  document.body.clientHeight || document.documentElement.clientHeight;
	if(_h>613) {
		$('bodyBackgroundD').style.height = _h - 313 + 'px'; 
	}
	*/
}


/**
 * 复制一个一样的对象
 * @param obj1
 * @return
 */
function copyObj(obj1) {
	var obj2 = {};
	for(var p in obj1) {
		obj2[p] = obj1[p];
	}
	return obj2;
}

/**
 * 向下拉框里添加元素
 * @param sel
 * @param objs
 * @return
 */
function putElesToSelectOption(sel, objs) {
	var se = ff(sel);
	if(!se) se = sel;
	for(var i=0; i<objs.length; i++) {
		var opt = new Option(objs[i].varName, objs[i].varIndex);
		se.options[i] = opt;
	}
}

/**
 * 建一个半透明层盖在页面上
 * @return
 */
function createDiscoverDiv() {
	var width = document.body.clientWidth || document.documentElement.clientWidth; //document.body.scrollWidth;//window.screen.width;//document.body.offsetWidth;//window.screen.availWidth;//document.body.clientWidth;
	var height = document.body.clientHeight || document.documentElement.clientHeight; //document.body.scrollHeight;//window.screen.height;//document.body.offsetHeight;//window.screen.availHeight;//document.body.clientHeight;
	//alert(width);
	var discover = ffC('div');
	discover.style.position = 'absolute';
	discover.style.top = '0px';
	discover.style.left = '0px';
	discover.style.width = width + 'px';
	discover.style.height = height + 'px';
	//discover.style.background = '#987cb9';
	discover.style.background = '#000000';
	discover.style.filter="Alpha(Opacity=20)";
	discover.style.MozOpacity="0.2";
	discover.style.zIndex = 900;
	document.body.appendChild(discover);
	return discover;
}

/**
 * 把带有px的字符串去掉px后的整数数值
 * @param lenPx
 * @return
 */
function convertPxIntoInt(lenPx) {
	var i = lenPx.indexOf('px');
	return parseInt(lenPx.substring(0, i));
}

/**
 * 移除这一层
 * @param subDiv
 * @return
 */
function removeSubDiv(subDiv) {
	subDiv.parentNode.removeChild(subDiv);
}

/**
 * 取得屏幕中的上位置
 * @param e
 * @return
 */
function getTop(e){
	var offset=e.offsetTop;
	//alert(offset);
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
	return offset;
}

/**
 * 取得屏幕中的左位置
 * @param e
 * @return
 */
function getLeft(e){
	var offset=e.offsetLeft;
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
	return offset;
}

/**
 * 拖动层移动位置
 * @param dragArea 拖动层
 * @param moveDiv 移动层（移动时，去除中间层，改变样式为透明，停止后切换回来）
 * @param _inputDiv 内部切换层
 * @return
 */
function dragAndMoveDiv(dragArea, moveDiv, _inputDiv){
	dragArea.onselectstart=function() {return(false)};
	dragArea.onmousedown = function(e){
		e = e || window.event;
		var x = e.clientX;
		var y = e.clientY;
		dragArea.cancelBubble = true;
		
		moveDiv.removeChild(_inputDiv);
		moveDiv.style.filter="Alpha(Opacity=20)";
		moveDiv.style.MozOpacity="0.2";
		moveDiv.style.background = "yellow";
		
		document.onmousemove=function(e){
		   e=e||window.event;
		   moveDiv.style.left=parseInt(moveDiv.style.left) + (e.clientX-x)+"px";
		   moveDiv.style.top=parseInt(moveDiv.style.top)+(e.clientY-y)+"px";
		   x = e.clientX;
		   y = e.clientY;
		};
		document.onmouseup=function(){document.onmousemove=null;};
	}
	dragArea.onmouseup = function(e) {
		moveDiv.appendChild(_inputDiv);
		moveDiv.style.filter=null;
		moveDiv.style.MozOpacity=null;
		moveDiv.style.background = "#ffffff";
	}
}

/**
 * 返回删除某个元素后的该数组
 * @param {} ary
 * @param {} ele
 * @return {}
 */
function delFromArray(ary, ele) {
	var _ary = [];
	for(var i=0; i<ary.length; i++) {
		var _ele = ary[i];
		if (_ele != ele) {
			_ary.push(_ele);
		}
	}
	return _ary ;
}

/**
 * 判断出该数组中是否存在某个元素
 * @param {} ary
 * @param {} ele
 * @return {Boolean}
 */
function isExisted(ary, ele) {
	for(var i=0; i<ary.length; i++) {
		if(ele == ary[i]) {
			return true;
		}
	}
	return false;
}

/**
 * 判断store里的记录是否为空
 * @param {} item_store
 * @return {Boolean}
 */
function isRecordNULL(item_store) {
	var items = item_store.data.items;

	if(items.length == 0) {
		return true;
	}
	return false;
}

function ff( element ) {
	if (Object.isString(element))
   		return document.getElementById(element);
	return element;
}

function ffA(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}

function ffC(tagName) {
	return document.createElement( tagName );
}

Object.extend = function(destination, source) {
	for (var property in source)
		destination[property] = source[property];
	return destination;
};

Object.extend(Object, {
	isFunction: function(object) {
		return typeof object == "function";
	},
	isString: function(object) {
		return typeof object == "string";
	},
	isNumber: function(object) {
		return typeof object == "number";
	},
	isUndefined: function(object) {
		return typeof object == "undefined";
	}
});

Object.extend(Function.prototype, {
  bind: function() {
    if (arguments.length < 2 && arguments[0] === undefined) return this;
    var __method = this, args = ffA(arguments), object = args.shift();
    return function() {
      return __method.apply(object, args.concat(ffA(arguments)));
    }
  },
  bindAsEventListener: function() {
    var __method = this, args = ffA(arguments), object = args.shift();
    return function(event) {
      return __method.apply(object, [event || window.event].concat(args));
    }
  }
});
